package quoridorTest;


import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import quoridor.Validator;

public class ValidatorTest {
	Validator theValidator;
	String testString = null;
	@Before
	public void setUp() throws Exception {
		theValidator = new Validator();
	}
	
	void checkValid () {
		assertTrue(theValidator.check(testString));
	}
	
	void checkInvalid() {
		assertFalse(theValidator.check(testString));
	}
	
	@Test
	public void testEmpty() {
		testString = "";
		checkValid();
	}
	
	@Test
	public void testMoveVerySimple() {
		testString = "e8";
		checkValid();
		
		testString = "e8 e2";
		checkValid();
		
		testString = "e1";
		checkInvalid();
		
		testString = "e8 e3";
		checkInvalid();
	}
	
	@Test
	public void testDirections() {
		testString = "e8 e2 e7";
		checkValid();
		testString = "e8 e2 e9";
		checkValid();
		testString = "e8 e2 d8";
		checkValid();
		testString = "e8 e2 f8";
		checkValid();
		
		testString = "e8 e2 e7 e1";
		checkValid();
		testString = "e8 e2 e9 e3";
		checkValid();
		testString = "e8 e2 d8 d2";
		checkValid();
		testString = "e8 e2 f8 f2";
		checkValid();
	}
	
	@Test
	public void testValidPawnJumpsSimple () {
		testString = "e8 e2 e7 e3 e6 e4 e5 e6";
		checkValid();
	}
	
	@Test
	public void testValidPawnJumpsLessSimple () {
		testString = "e8 d1 e7 e1 e6 d1 e5 e1 e4 d1 e3 e1 e2 b4h d1";
		checkValid();
		testString = "e8 d1 e7 e1 e6 d1 e5 e1 e4 d1 e3 e1 e2 b4h f1";
		checkValid();
		
		testString = "e8 d1 e7 e1 e6 d1 e5 e1 e4 d1 e3 e1 e2 b4h e1";
		checkInvalid();
		testString = "e8 d1 e7 e1 e6 d1 e5 e1 e4 d1 e3 e1 e2 b4h c1";
		checkInvalid();
		testString = "e8 d1 e7 e1 e6 d1 e5 e1 e4 d1 e3 e1 e2 b4h g1";
		checkInvalid();
	}
	
	@Test
	public void testInvalidPawnJumps() {
		
	}
	
	@Test
	public void testFencesSimple() {
		testString = "a1h";
		checkValid();
	}
	
	@Test
	public void testFencesStillSimple() {
		testString = "a1h c1h";
		checkValid();
	}
	
	@Test
	public void testFencesBottomEdge() {
		testString = "a9h";
		checkInvalid();
		testString = "a9v";
		checkInvalid();
		testString = "b9h";
		checkInvalid();
		testString = "b9v";
		checkInvalid();
		testString = "c9h";
		checkInvalid();
		testString = "c9v";
		checkInvalid();
		testString = "d9h";
		checkInvalid();
		testString = "d9v";
		checkInvalid();
		testString = "e9h";
		checkInvalid();
		testString = "e9v";
		checkInvalid();
		testString = "f9h";
		checkInvalid();
		testString = "f9v";
		checkInvalid();
		testString = "g9h";
		checkInvalid();
		testString = "g9v";
		checkInvalid();
		testString = "h9h";
		checkInvalid();
		testString = "h9v";
		checkInvalid();
		testString = "i9h";
		checkInvalid();
		testString = "i9v";
		checkInvalid();
	}
	
	@Test
	public void testFencesRightEdge() {
		testString = "i1h";
		checkInvalid();
		testString = "i1v";
		checkInvalid();
		testString = "i2h";
		checkInvalid();
		testString = "i2v";
		checkInvalid();
		testString = "i3h";
		checkInvalid();
		testString = "i3v";
		checkInvalid();
		testString = "i4h";
		checkInvalid();
		testString = "i4v";
		checkInvalid();
		testString = "i5h";
		checkInvalid();
		testString = "i5v";
		checkInvalid();
		testString = "i6h";
		checkInvalid();
		testString = "i6v";
		checkInvalid();
		testString = "i7h";
		checkInvalid();
		testString = "i7v";
		checkInvalid();
		testString = "i8h";
		checkInvalid();
		testString = "i8v";
		checkInvalid();
		testString = "i9h";
		checkInvalid();
		testString = "i9v";
		checkInvalid();
	}
	
	
	@Test
	public void testFencesNumber() {
		testString = "a1h c1h f1h h1h a2h c2h f2h h2h a3h c3h f3h h3h a4h c4h f4h h4h a5h c5h f5h h5h";
		checkValid();
		testString = "a1h c1h f1h h1h a2h c2h f2h h2h a3h c3h f3h h3h a4h c4h f4h h4h a5h c5h f5h h5h a6h c6h";
		checkInvalid();
		testString = "a1h c1h f1h h1h a2h c2h f2h h2h a3h c3h f3h h3h a4h c4h f4h h4h a5h c5h f5h h5h a6h";
		checkInvalid();
	}

}
